package com.rose.springbootgeneratefile.codegen.mybatis3.elements;

import com.rose.springbootgeneratefile.api.IntrospectedTable;
import com.rose.springbootgeneratefile.api.dom.java.*;
import com.rose.springbootgeneratefile.config.Context;

import java.util.Set;
import java.util.TreeSet;

public class MapperMethodGenerator extends AbstractJavaMethodGenerator {
    public MapperMethodGenerator(Context context, IntrospectedTable introspectedTable) {
        super();
        this.introspectedTable=introspectedTable;
        this.context=context;
    }

    @Override
    public void insert(Interface interfaze) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = new Method();

        method.setReturnType(FullyQualifiedJavaType.getIntInstance());
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setName("insert");

        FullyQualifiedJavaType parameterType;
//        if (isSimple) {
            parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
//        } else {
//            parameterType = introspectedTable.getRules()
//                    .calculateAllFieldsClass();
//        }

        importedTypes.add(parameterType);
        method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

        context.getCommentGenerator().addGeneralMethodComment(method,
                introspectedTable);

        addMapperAnnotations(interfaze, method);

//        if (context.getPlugins().clientInsertMethodGenerated(method, interfaze,
//                introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
//        }
    }

    public void addMapperAnnotations(Interface interfaze, Method method) {
    }
}

